home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gcc / ixemul_src.lha / ixemul-41.0 / library / ix_patch_functions.c < prev    next >
C/C++ Source or Header  |  1995-05-22  |  8KB  |  230 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  *  $Id: ix_patch_functions.c,v 1.5 1994/06/25 11:58:21 rluebbert Exp $
  21.  *
  22.  *  $Log: ix_patch_functions.c,v $
  23.  *  Revision 1.5  1994/06/25  11:58:21  rluebbert
  24.  *  Moved pow to within ifndef __HAVE_68881
  25.  *
  26.  *  Revision 1.4  1994/06/19  15:13:10  rluebbert
  27.  *  *** empty log message ***
  28.  *
  29.  *  Revision 1.2  1992/08/09  20:54:44  amiga
  30.  *  add panic functions for systems not having some math librar{ies,y}
  31.  *
  32.  *  Revision 1.1  1992/05/14  19:55:40  mwild
  33.  *  Initial revision
  34.  *
  35.  */
  36.  
  37. #define KERNEL
  38. #include "ixemul.h"
  39.  
  40. #ifndef AFF_68030
  41. #define AFF_68030    (1L<<2)
  42. #define AFF_68040    (1L<<3)
  43. #endif
  44.  
  45. extern struct ExecBase *SysBase;
  46.  
  47. extern void *MathIeeeDoubTransBase, *MathIeeeDoubBasBase, *MathIeeeSingBasBase;
  48.  
  49.  
  50. /*
  51.  * Note: these functions don't really return void, this is just to
  52.  *       declare them as functions, so that the table below is generated
  53.  *       right.
  54.  */
  55. #if 0 /* now automatically included when building ixemul.library with -m68881 */
  56. extern void __divsi3_20(), __udivsi3_20(),  __umodsi3_20(),  __modsi3_20(), 
  57.     __mulsi3_20(), __umulsi3_20();
  58. extern void __adddf3_20(), __addsf3_20(), __cmpdf2_20(), __cmpsf2_20(),
  59.             __divdf3_20(), __divsf3_20(),  __extendsfdf2_20(), 
  60.             __fabs_20(), __fixdfsi_20(), __fixunsdfsi_20(), __floatsidf_20(), 
  61.             frexp_20(), ldexp_20(), modf_20(), __muldf3_20(),
  62.             __mulsf3_20(), __negdf2_20(), __negsf2_20(), 
  63.             __subdf3_20(), __subsf3_20(), __truncdfsf2_20();
  64. #endif
  65.  
  66. /*
  67.  * Property flags. These characterize the used machine, and enable alternate
  68.  * functions specified in the following table.
  69.  * The MMU properties are for the later implementation of virtual memory ;-))
  70.  */
  71.  
  72. /* requires a 68030 MMU (this works for the 68851 as well, no TT regs are used */
  73. #define PF_FULL_MMU    (1<<0)
  74. /* this works with a 68040 MMU.
  75.  * NOTE: a 68030 can use this function as well, but a 68040 can't use PF_FULL_MMU
  76.  */
  77. #define PF_REDU_MMU    (1<<1)
  78.  
  79. /* a 68020 or higher required */
  80. #define PF_32BITCPU    (1<<5)
  81. /* an fpu required. */
  82. #define PF_FPU        (1<<6)
  83.  
  84. /* these are `negative' property flags, they indicate that an optional library
  85.    is missing. */
  86. /* no mathieeedoubtrans.library */
  87. #define PF_NODT        (1<<29)
  88. /* no mathieeedoubbas.library */
  89. #define PF_NODB        (1<<30)
  90. /* no mathieeesingbas.library */
  91. #define PF_NOSB        (1<<31)
  92.  
  93. /* panic functions if a function requiring a not available library is invoked */
  94. static void panic_nodt () { ix_panic ("mathieeedoubtrans.library required!"); _exit (1); }
  95. static void panic_nodb () { ix_panic ("mathieeedoubbas.library required!"); _exit (1); }
  96. static void panic_nosb () { ix_panic ("mathieeesingbas.library required!"); _exit (1); }
  97.  
  98.  
  99. /*
  100.  * This table defines, which library functions should be replaced by an alternate
  101.  * function, this replacement should happen, if one of the specified flags is
  102.  * true for the current system configuration
  103.  *
  104.  * Place panic stubs for not available libraries before cpu replacements, that
  105.  * way you can get away without mathieeesingbas.library if you have an fpu, for
  106.  * example.
  107.  */
  108.  
  109. struct patch_table {
  110.   enum _syscall_ pt_entry;    /* the slot to replace */
  111.   void         (*pt_func)();    /* some `prototype', no void result required */
  112.   u_int         pt_flags;    /* all needed properties */
  113. } ix_patch_table[] = {
  114.   /* basic math support requiring mathieee{sing,doub}bas.library */
  115. #ifndef __HAVE_68881
  116.   SYS___adddf3,        panic_nodb,        PF_NODB,
  117.   SYS___addsf3,        panic_nosb,        PF_NOSB,
  118.   SYS___cmpdf2,        panic_nodb,        PF_NODB,
  119.   SYS___cmpsf2,        panic_nosb,        PF_NOSB,
  120.   SYS___divdf3,        panic_nodb,        PF_NODB,
  121.   SYS___divsf3,        panic_nosb,        PF_NOSB,
  122.   SYS___extendsfdf2,    panic_nodb,        PF_NODB,
  123.   SYS___fixdfsi,    panic_nodb,        PF_NODB,
  124.   SYS___fixunsdfsi,    panic_nodb,        PF_NODB,
  125.   SYS___floatsidf,    panic_nodb,        PF_NODB,
  126.   SYS_frexp,        panic_nodb,        PF_NODB,
  127.   SYS_ldexp,        panic_nodb,        PF_NODB,
  128.   SYS_modf,        panic_nodb,        PF_NODB,
  129.   SYS___muldf3,        panic_nodb,        PF_NODB,
  130.   SYS___mulsf3,        panic_nosb,        PF_NOSB,
  131.   SYS___negdf2,        panic_nodb,        PF_NODB,
  132.   SYS___negsf2,        panic_nosb,        PF_NOSB,
  133.   SYS___subdf3,        panic_nodb,        PF_NODB,
  134.   SYS___subsf3,        panic_nosb,        PF_NOSB,
  135.   SYS___truncdfsf2,    panic_nodb,        PF_NODB,
  136.  
  137.   /* transcendental functions, mathieeedoubtrans.library */
  138.   SYS_atan,        panic_nodt,        PF_NODT,
  139.   SYS_sin,        panic_nodt,        PF_NODT,
  140.   SYS_cos,        panic_nodt,        PF_NODT,
  141.   SYS_tan,        panic_nodt,        PF_NODT,
  142.   SYS_sinh,        panic_nodt,        PF_NODT,
  143.   SYS_cosh,        panic_nodt,        PF_NODT,
  144.   SYS_tanh,        panic_nodt,        PF_NODT,
  145.   SYS_exp,        panic_nodt,        PF_NODT,
  146.   SYS_log,        panic_nodt,        PF_NODT,
  147.   SYS_sqrt,        panic_nodt,        PF_NODT,
  148.   SYS_asin,        panic_nodt,        PF_NODT,
  149.   SYS_acos,        panic_nodt,        PF_NODT,
  150.   SYS_log10,        panic_nodt,        PF_NODT,
  151.   SYS_floor,        panic_nodb,        PF_NODB,
  152.   SYS_ceil,        panic_nodb,        PF_NODB,
  153.   SYS_pow,        panic_nodt,        PF_NODT,
  154. #endif
  155.   SYS_sincos,        panic_nodt,        PF_NODT,
  156.  
  157.   /* fpu/mmu support */
  158. #if 0 /* included in build, no longer needed */
  159.   SYS___adddf3,        __adddf3_20,        PF_FPU,
  160.   SYS___addsf3,        __addsf3_20,        PF_FPU,
  161.   SYS___cmpdf2,        __cmpdf2_20,        PF_FPU,
  162.   SYS___cmpsf2,        __cmpsf2_20,        PF_FPU,
  163.   SYS___divdf3,        __divdf3_20,        PF_FPU,
  164.   SYS___divsf3,        __divsf3_20,        PF_FPU,
  165.   SYS___extendsfdf2,    __extendsfdf2_20,    PF_FPU,
  166.   SYS___fixdfsi,    __fixdfsi_20,        PF_FPU,
  167.   SYS___fixunsdfsi,    __fixunsdfsi_20,    PF_FPU,
  168.   SYS___floatsidf,    __floatsidf_20,        PF_FPU,
  169.   SYS_frexp,        frexp_20,        PF_FPU,
  170.   SYS_ldexp,        ldexp_20,        PF_FPU,
  171.   SYS_modf,        modf_20,        PF_FPU,
  172.   SYS___muldf3,        __muldf3_20,        PF_FPU,
  173.   SYS___mulsf3,        __mulsf3_20,        PF_FPU,
  174.   SYS___negdf2,        __negdf2_20,        PF_FPU,
  175.   SYS___negsf2,        __negsf2_20,        PF_FPU,
  176.   SYS___subdf3,        __subdf3_20,        PF_FPU,
  177.   SYS___subsf3,        __subsf3_20,        PF_FPU,
  178.   SYS___truncdfsf2,    __truncdfsf2_20,    PF_FPU,
  179. #endif
  180.  
  181. #if 0 /* Included in build if 68020 or higher; no longer needed. */
  182.   SYS___divsi3,        __divsi3_20,        PF_32BITCPU,
  183.   SYS___modsi3,        __modsi3_20,        PF_32BITCPU,
  184.   SYS___mulsi3,        __mulsi3_20,        PF_32BITCPU,
  185.   SYS___udivsi3,    __udivsi3_20,        PF_32BITCPU,
  186.   SYS___umodsi3,    __umodsi3_20,        PF_32BITCPU,
  187. #endif
  188. };
  189.  
  190. void
  191. ix_patch_functions (struct ixemul_base *ixbase)
  192. {
  193.   u_int pflags;
  194.   struct patch_table *pt;
  195.  
  196.   pflags = 0;
  197.  
  198.   /* try to figure out properties from the AttnFlags in ExecBase. Later on
  199.    * we'll have to decide as well on some user-specified flags (for example
  200.    * whether virtual memory should be enabled, and probably others as well ;-))
  201.    */
  202.  
  203.   /* AFF_68020 is set for any 68020, 68030, 68040... */
  204. #if defined (m68020) || defined (m68030) || defined (m68040) || defined (m68060)
  205.     pflags |= PF_32BITCPU;
  206. #endif
  207. #ifdef __HAVE_68881
  208.     pflags |= PF_FPU;
  209. #endif
  210.  
  211.   /* add negative property flags */
  212.   if (! MathIeeeDoubTransBase)
  213.     pflags |= PF_NODT;
  214.   if (! MathIeeeDoubBasBase)
  215.     pflags |= PF_NODB;
  216.   if (! MathIeeeSingBasBase)
  217.     pflags |= PF_NOSB;
  218.  
  219.   /*
  220.    * if the machine hasn't any special properties, just return
  221.    */
  222. if (! pflags) return;
  223.   for (pt = ix_patch_table; 
  224.        pt < &ix_patch_table[sizeof (ix_patch_table)/sizeof (struct patch_table)];
  225.        pt++)
  226.     if (pt->pt_flags & pflags)
  227.         SetFunction ((struct Library *)ixbase, -6*(pt->pt_entry + 4), (unsigned long (*)()) pt->pt_func);
  228.         /* -6*(s + 4) converts syscall# into _LVO */
  229. }
  230.